#include "StdAfx.h"
#include "Game.h"
#include "ResManager.h"
#include "StateMachine.h"
#include "DrawWindow.h"
#include "Elements.h"
#include "SelectionSystem.h"
#include "FightingSystem.h"

Game::Game(){
	QuitingGame = false;
	Pause = true;
	SM = 0;
	RM = 0;
	T = 0;
	MW = 0;
	BG =0;
	FTR[0] = FTR[1] = 0;

	//BG.SetDrawWindow(&MW); 
	//FTR[0].SetDrawWindow(&MW);
	//FTR[1].SetDrawWindow(&MW);
}

void Game::Run(){
	//MW->Create();
	SM->BeginGame();

	T->LimitThreadAffinityToCurrentProc();
	T->Start();

	while(!QuitingGame){
		//One Frame...
		if(!MW->IsProcessingMessage()){
			MW->WaitTilOkToDrawFrame();
			SM->DrawAsCurrentState();
			MW->Present();
		}
	}//while
	MW->Finish();
}

void Game::Initiate(HINSTANCE h){
	hInstance = h;
	T = new CTimer();
	RM = new ResourceManager(hInstance);
	SM = new StateMachine( );
	MW = new DrawWindow(RM, T);
	FSS = new SelectionSystem( );
	INP = new InputData();
	FBI = new ObjectInfo(RM);
	CS = new CombatSystem();
}

void Game::Cleanup(){
	if(CS) delete CS;
	if(FBI) delete FBI; 
	if(INP) delete INP; 
	if(FSS) delete FSS;
	if(MW) delete MW;
	if(T) delete T; 
	if(RM) delete RM; 
	if(SM) delete SM;
}